package com.com.corejavalearnings.reflection;

import java.lang.reflect.Field;

/**
 * Created by pankaj on 7/30/15.
 */
public class Reflection {

    public static void main(String[] args) {
        Loader2 loader = new Loader2(Model.class);
        Model model = (Model)loader.load();
        System.out.println(model);

    }
}
class Loader2
{
    Class clazz;

    Loader2() {
    }

    Loader2(Class clazz) {
        this.clazz = clazz;
    }

    protected Object load()
    {
        try {
            Object obj = clazz.newInstance();
            for(Field field : obj.getClass().getFields())
            {
                System.out.print("\n"+field.getName());
                System.out.println("->" + field.get(obj));
                field.set(obj, "mysql");
                System.out.print(field.getName());
                System.out.println("->"+field.get(obj));
            }
            return obj;
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }
        return new IllegalStateException("Should not be here!!!!");
    }
}